<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Token;
use app;
use app\admin\model\AdminLog;


class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {
        //banner图
        $ad_row=db('hs_ad')->where('ad_location=1')->find();//
        $this->assign('ad_row',$ad_row);
        
        //招聘列表
        $rec_list=db('hs_recruit')->where("status!='end'")->order('recruit_id desc')->paginate(12);
        $this->assign('rec_list',$rec_list);
        
        return $this->view->fetch();
    }
    public function info()
    {
        
        //banner图
        $ad_row=db('hs_ad')->where('ad_location=2')->where('status','normal')->select();//
        $this->assign('ad_row',$ad_row);
        
        $rec_id=$this->request->param('recruit_id');
        $rec_row=db('hs_recruit')->where('recruit_id',$rec_id)->find();//招聘信息
        $step_list=db('hs_recruit_step')->where('recruit_id',$rec_id)->order('sort asc')->select();//流程
        $num=1;
        foreach ($step_list as &$step){
            $step['num']=$num++;
            if($step['status']=='wait'){
                $step['status_name']='未开始';
            }elseif($step['status']=='doing'){
                $step['status_name']='进行中';
            }elseif($step['status']=='end'){
                $step['status_name']='已结束';
            }
        }
        $post_list=db('hs_recruit_post')->where('recruit_id',$rec_id)->order('post_id desc')->select();//岗位
        
        $this->view->assign('rec_row',$rec_row);
        $this->view->assign('step_list',$step_list);
        $this->view->assign('post_list',$post_list);
        
        
        //查询当前流程内容
        $step_id=$this->request->param('step_id','');
        if(!$step_id){
            $step_id=db('hs_recruit_step')
                    ->where('recruit_id',$rec_id)
                    ->where('status','doing')
                    ->order('sort asc')
                    ->value('step_id');//流程
        }
        if($step_id){
            $step_row=db('hs_recruit_step')->where('step_id',$step_id)->find();
            if($step_row['status']=='wait'){
                $step_row['status_name']='未开始';
            }elseif($step_row['status']=='doing'){
                $step_row['status_name']='进行中';
            }elseif($step_row['status']=='end'){
                $step_row['status_name']='已结束';
            }
        }else{
            $step_row['status']='已结束';
            $step_row['step_name']='公告';
            $step_row['step_content']='招聘已结束';
            
        }
        $this->assign('step_row',$step_row);
        //判断报名按钮
        $this->assign('apply','apply');
        
        return $this->view->fetch();
    }

    
    public function news()
    {
        $newslist = [];
        return jsonp(['newslist' => $newslist, 'new' => count($newslist), 'url' => 'https://www.fastadmin.net?ref=news']);
    }

}
